package com.iseastar.guojiang.cabinet;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.iseastar.BaseActivity2;
import com.iseastar.guojiang.app.Intents;
import com.iseastar.guojiang.logic.AppHttp;
import com.iseastar.guojiang.model.OrderBean;
import com.iseastar.guojiang.order.OrderPictureCheckActivity;
import com.iseastar.guojiang.order.OrderRefuseActivity;
import com.shouhuobao.station.R;

import droid.frame.activity.title.TitleRes;

/**
 * 智能柜、包裹列表、详情
 *
 * @author coffee<br>
 *         2016-12-21下午6:14:06
 */
public class CabinetParcelDetailActivity extends BaseActivity2 implements OnClickListener {

	private OrderBean order;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		order = (OrderBean) getIntent().getSerializableExtra("item");
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void findViewById() {
		setContentView(R.layout.cabinet_order_details);
		super.findViewById();
		getAppTitle().setCommonTitle("订单详情", new TitleRes("拒收", new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(getContext(), OrderRefuseActivity.class);
				intent.putExtra("itemId", order.getId());
				startActivityForResult(intent, 102);
			}
		}));
		// 投递袋
		TextView bagCode = (TextView) findViewById(R.id.order_detail_bagcode);
		bagCode.setText(order.getBagCode());
		// 用户电话
		TextView phone = (TextView) findViewById(R.id.order_detail_phone);
		phone.setText(order.getSenderPhone());
		// 下单时间
		TextView orderTime = (TextView) findViewById(R.id.order_submit_time);
		orderTime.setText("下单时间:" + order.getOrderTime());
		// 投递时间
		TextView postTime = (TextView) findViewById(R.id.order_post_time);
		postTime.setText("投递时间: " + order.getPostTime());
		// 包裹图片
		ImageView image = (ImageView) findViewById(R.id.order_parcel_image);
		AppHttp.getInstance().loadImage(order.getParcelImgUrl(), image);
		// 电话
		findViewById(R.id.order_phone_call).setOnClickListener(this);
		// 大图
		findViewById(R.id.order_parcel_image_layout).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			// 拨打用户电话
			case R.id.order_phone_call:
				Intents.dialOrCall(order.getSenderPhone());
				break;
			// 查看大图
			case R.id.order_parcel_image_layout:
				Intent intent = new Intent();
				intent.setClass(getContext(), OrderPictureCheckActivity.class);
				intent.putExtra("picUrl", order.getParcelImgUrl());
				startActivity(intent);
				break;
		}
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// 拒收--回调(直接关闭该界面)
		if (requestCode == 102 && resultCode == RESULT_OK) {
			finish();
		}
	}

}
